faApp.controller('ActivityAddCtrl',['$scope','activityService','$location','$controller','$route', '$filter', function($scope,activityService,$location,$controller,$route, $filter) {
  $scope.ctrlName = "ActivityAddCtrl";
  $scope.activityId = $location.search().activityId || '';
  
  $scope.activity = {
    activitiesName: '',
    activitiesDesc: '',
    activitiesSkipName: '',
    activitiesSkipLink: '',
    activitiesStartDateStr: '',
    activitiesEndDateStr: '',
    activitiesStatus: '01'
  };

  if($scope.activityId){
    activityService.activityById({id: $scope.activityId}).then(function(json){
      if (json.statusCode){
       alert(json.statusCode);
      }else{
        $scope.activity = json.projectActivities;

        $scope.activity.activitiesStartDateStr = $filter('date')(json.projectActivities.activitiesStartDate, "yyyy-MM-dd");
        $scope.activity.activitiesEndDateStr = $filter('date')(json.projectActivities.activitiesEndDate, "yyyy-MM-dd");
      }
    });
  }

  $scope.save = function(){
    if(!$scope.form.$invalid){
      var p = {};
      if ($scope.activityId){
        p = activityService.activityEdit;

        $scope.activity.activitiesStartDate = '';
        $scope.activity.activitiesEndDate = '';
      }else{
        p = activityService.activityAdd;
      }

      if((!$scope.activity.activitiesSkipName && $scope.activity.activitiesSkipLink) ||
         ($scope.activity.activitiesSkipName && !$scope.activity.activitiesSkipLink)){
        alert('活动产品专题跳转名称和活动专题跳转链接 必须都填写或不填写！');
        return;
      }

      p($scope.activity).then(function(json){
        if (json.statusCode){
          if(json.statusCode == '4015'){
            alert('活动Code已存在，请更换！');
          }else{
            alert(json.statusCode);
          }
        }else{
          alert('SUCCESS！');
          $location.path("/activity/list");
        }
      });
    }
  };

}]);

faApp.controller('ActivityListCtrl',['$scope','activityService','$location','$controller','$route',function($scope,activityService,$location,$controller,$route) {   
  $scope.ctrlName = "ActivityListCtrl";
  
  $scope.activityList = {};
  $scope.pager = {};

  $scope.config = {
    "pageSize" : 20,
    "pageNo" : 1
  };

  $scope.$watch('config',function(){
    activityService.activityList($scope.config).then(function(json){
      console.log(json);
      $scope.activityList = json.list;
      $scope.pager = json.pager;
    });
  },true);

}]);